package com.springboot.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.springboot.model.po.Business;
import com.springboot.service.BusinessService;

@RefreshScope	//监听动态刷新
@RestController
@RequestMapping("/business")
public class BusinessController {
	@Autowired
	BusinessService businessService;
	
	@GetMapping("/{businessId}")
	public ResponseEntity getBusinessById(@PathVariable Integer businessId) throws Exception{
		Business business = businessService.getBusinessById(businessId);		
		if(business == null) {
			return ResponseEntity.status(HttpStatus.NOT_FOUND).body("The requested resource was not found");
		}else{
			return ResponseEntity.ok(business);
		}
	}
	
	@GetMapping("/orderType/{orderTypeId}")
	public ResponseEntity listBusinessByOrderTypeId(@PathVariable Integer orderTypeId) throws Exception{
		List<Business> list = businessService.listBusinessByOrderTypeId(orderTypeId);
		if(list.size() == 0 || list == null) {
			return ResponseEntity.status(HttpStatus.NOT_FOUND).body("The requested resource was not found");
		}else {
			return ResponseEntity.ok(list);
		}
	}
}
